<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.ufida.com/multilang" prefix="ml" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %>
<%@ page import="nc.lfw.core.LfwRuntimeEnvironment"%>
<html>
	<head>
		<lfw:base/> 
		<lfw:head/>
		<uif:import/>
		<uif:webbximport/>
		<script type='text/javascript' src='<%= "code/" + request.getParameter("pageId")%>'></script>
		<script type='text/javascript' src='${ROOT_PATH}/html/nodes/report/reportquery/reportqueryutil.js'></script>
		<script type='text/javascript' src='${ROOT_PATH}/html/nodes/report/reportutil.js'></script>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()">
		<lfw:pageModel className="nc.lfw.finance.report.ReportQueryPageModel">
			<lfw:layout type="flowv" border="0">
				<lfw:layoutPanel height="10" align="left">
					<font size="12"> ${ml:trans('yer_reportqry_label')}</font>
				</lfw:layoutPanel>
				<lfw:layoutPanel height="50" width="100%">
					<lfw:grid id="queryGrid"/>
				</lfw:layoutPanel >
				<lfw:layoutPanel height="30">
					<lfw:form id="queryForm"></lfw:form>
				</lfw:layoutPanel>
				<%--   暂不支持  显示凭证
				<lfw:layoutPanel height="10">
					<lfw:checkbox id="isShow"></lfw:checkbox>
				</lfw:layoutPanel>
				--%>
				<lfw:layoutPanel height="10">
					<lfw:layout type="flowh" border="0">
						<lfw:layoutPanel width="10%" align="left" height="10">
							<lfw:label id="ddwxz_label"></lfw:label>
						</lfw:layoutPanel>
						<lfw:layoutPanel width="20%" align="left" height="10">
							<div id="mult_corp_div"></div>
						</lfw:layoutPanel>
						<lfw:layoutPanel width="70%">
							&nbsp;
						</lfw:layoutPanel>
					</lfw:layout>
				</lfw:layoutPanel>
				<lfw:layoutPanel height='30'>
					<div id="fix_div" style="height:30"></div>
				</lfw:layoutPanel> 
				<lfw:layoutPanel height='10'>
					<lfw:layout type="flowh" border="0">
						<lfw:layoutPanel width="45%" align="right" >
							<lfw:button id="query_confirm"></lfw:button>
						</lfw:layoutPanel>
						<lfw:layoutPanel width="10%">
							&nbsp;
						</lfw:layoutPanel>
						<lfw:layoutPanel width="45%" align="left" >
							<lfw:button id="query_cancelBt"></lfw:button>
						</lfw:layoutPanel>	
					</lfw:layout>
				</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>
<script>
	function afterPageInit(){ 
	}
	function externalInit(){
		var fixConDs = getDataset('fixConDs');
		if(fixConDs != null && fixConDs.getRowCount() != 0){
			for(var i=0,len=fixConDs.getRowCount(); i<len; i++){
				var row = fixConDs.getRow(i);
				var key = row.getCellValue(0);
				var labelComp = key + "LabelComp";
				labelComp = new LabelComp(document.getElementById("fix_div"), 'fix_label_'+key, 10, 340 + i*20, row.getCellValue(1)+":", 'absolute');
				
				var textComp = key + "TextComp"; 
				textComp = new StringTextComp(document.getElementById("fix_div"), "fix_comp_"+key, 100, 340 + i*20, 200, 'absolute', {"disabled": 'false',"readOnly":'true'}, "text_form_div");
				textComp.setValue(row.getCellValue(4));
				textComp.setActive(false);
			}
		}	
		var ds = getDataset('queryTemplateDs');
  		ds.onAfterDataChange = function(event, pageIndex) {
  			this.clearState();
  			if(event.cellColIndex == 0){
				if(event.currentValue != event.oldValue){
					this.setValueAt(event.cellRowIndex,1,null);
					this.setValueAt(event.cellRowIndex,2,null);
					this.setValueAt(event.cellRowIndex,3,null);
					if(event.currentValue != '-1'){
						if(event.currentValue == 'jkbxr' || event.currentValue == 'szxmid' 
							|| event.currentValue == 'jobid'){//根据选择的查询对象 设置sql
							this.setValueAt(event.cellRowIndex,5,'fb');
						}
						else{
							this.setValueAt(event.cellRowIndex,5,'zb');
						}
					}
				}
  			}
  		};
  		
  		var ds = getDataset('queryFormDs');
  		ds.setRowSelected(0);
  		setTimeout("initData()",200);
  		
  		var form = getComponent('queryForm')
		var ele = form.getElement('querytype_combo');
		var layout = form.pLayout;
		ele.valueChanged = function(newItem, lastItem){
			var value = newItem.value;
			if(value == 'month'){
				layout.getCompById('startdate').visible = false;
				layout.getCompById('enddate').visible = false;
				layout.getCompById('start_ref_name').visible = true;
				layout.getCompById('end_ref_name').visible = true;
				if(layout){
					layout.setForceRepaint(true);
					layout.paint();
				}	
			}else if(value == 'date'){
				layout.getCompById('startdate').visible = true;
				layout.getCompById('enddate').visible = true;
				layout.getCompById('start_ref_name').visible = false;
				layout.getCompById('end_ref_name').visible = false;
				if(layout){
		 			layout.setForceRepaint(true);
		 			layout.paint();
			 	}	
			}
		}
		//支持月份参照可手输入
		var ele1 = getComponent('queryForm').getElement('start_ref_name'); 
    	if(ele1 != null){
    		ele1.innerProcessEnter = function(){
    			if(!validateDate(ele1.getValue())){
    				showErrorDialog("${ml:trans('yer_report_formater')}");
    				ele1.setValue(null);
    			}
    		}
    	}
    	var ele2 = getComponent('queryForm').getElement('end_ref_name'); 
    	if(ele2 != null){
    		ele2.innerProcessEnter = function(){
    			if(!validateDate(ele2.getValue())){
    				showErrorDialog("${ml:trans('yer_report_formater')}");
    				ele2.setValue(null);
    			}
    		}
    	}
		
		var refTextComp = new ReferenceTextComp(document.getElementById("mult_corp_div"), 'mult_corp_comp', 0, 0, '120', 'relative', {"disabled": 'false',"readOnly":'false'}, getRefNodeInfo('mult_corp_ref'), 'text_form_div');
		ds.onAfterDataChange = function(event){
			if(event.cellColIndex == '11')
				refTextComp.setValue(event.currentValue);
			if(event.cellColIndex == '12')
				refTextComp.setValue('<%=LfwRuntimeEnvironment.getCorp().getUnitname()%>');
		};
		refTextComp.setReadOnly(true);
		window["$c_mult_corp_comp"] = refTextComp;
		initDefaultValue();
	}
	
	function validateDate(value){
		var t = /2[0-9]{2,3}[-](([0][1-9])|([1][0-2]))/;		
		if(!t.exec(value))
			return false;
		return true;  
	}
	
	function initDefaultValue()
	{
		var ds = getDataset('queryFormDs');
		var loginDate = getLoginDate();
		var loginMonth = loginDate.substring(0,7);
		ds.setValueAt(0, 0, '0');   //单据状态 
		ds.setValueAt(0, 1, 'date');//日期
		ds.setValueAt(0, 2, loginDate);
		ds.setValueAt(0, 3, loginDate);
		ds.setValueAt(0, 4, loginMonth);
		ds.setValueAt(0, 6, loginMonth);
		ds.setValueAt(0, 10, '0');//往来对象
		ds.setValueAt(0,12,getPkCorp());
	}
	
	/*动态设置参照*/
	function initData(){
		var ds = getDataset('queryTemplateDs');
		ds.setValueAt(0, 0, 'jkbxr');
		/*
		var grid = getComponent("queryGrid");
		for(var i=0,len=grid.getRowsNum(); i<len; i++){
			var ref = grid.compsMap.get("Reference" + i);
			if(ref != null)
				ref.setReadOnly(true);
		}
		*/
	}
	
	ReferenceTextComp.prototype.beforeOpenRefDialog = function()
	{
		if(this.datasetId != 'queryTemplateDs')
			return;
		var ds = getDataset('queryTemplateDs');
  		var row = ds.getSelectedRow();
  	  	var newValue = row.getCellValue(ds.nameToIndex('queryObj'));	
		if(newValue == null)
			return false;
  	  	var compsMap = getComponent("queryGrid").compsMap;
		var ref = getComponent("queryGrid").compsMap.get("Reference1");
		var refId = null;
		if(newValue == 'jkbxr')
			refId = 'ywy_ref';
		else if(newValue == 'deptid' || newValue == 'fydeptid')
			refId = 'dept_ref';
		else if(newValue == 'szxmid')
			refId = 'szxm_ref';
		else if(newValue == 'jobid')//项目
			refId = '';
		else if(newValue == 'fydwbm')
			refId = 'fydwbm_ref';
		var refInfo = getRefNodeInfo(refId);
		ref.nodeInfo = refInfo;
		ref.refreshDialog = true;
		return true;
	};
	
	GridComp.prototype.onCellClick = function(cell, rowIndex, colIndex)
	{
		var ds = getDataset('queryTemplateDs');
		if(rowIndex != 0 && colIndex == 0)
			ds.setValueAt(rowIndex,0,'-1');
	};
</script>	